home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / copascal.arc / INSYMBOL.MOD < prev    next >
Text File  |  1979-12-31  |  6KB  |  214 lines

  1. procedure INSYMBOL;     (* reads next symbol *)
  2. label 1,2,3;
  3. var I,J,K,E: integer;
  4.  
  5.   procedure READSCALE;
  6.   var S, SIGN: integer;
  7.   begin
  8.     NEXTCH;
  9.     SIGN := 1;
  10.     S := 0;
  11.     if CH = '+' then NEXTCH else
  12.       if CH = '-' then begin
  13.         NEXTCH;
  14.         SIGN := -1;
  15.       end;
  16.     if NOT (CH IN ['0'..'9'])
  17.       then ERROR(40)
  18.       else repeat
  19.         S := 10*S + ORD(CH) - ORD('0');
  20.         NEXTCH;
  21.       until NOT (CH IN ['0'..'9']);
  22.       E := S*SIGN + E;
  23.    end; { READSCALE }
  24.  
  25.    procedure ADJUSTSCALE;
  26.    var S   : integer;
  27.        D,T : real;
  28.    begin
  29.      if K+E > EMAX then ERROR(21)
  30.       else if K+E < EMIN then RNUM := 0
  31.         else begin
  32.           S := ABS(E);
  33.           T := 1.0;
  34.           D := 10.0;
  35.           repeat
  36.             while NOT ODD(S) do begin
  37.               S := S DIV 2;
  38.               D := SQR(D);
  39.             end;
  40.             S := S-1;
  41.             T := D*T;
  42.           until S = 0;
  43.           if E >= 0 then RNUM := RNUM*T
  44.                     else RNUM := RNUM/T;
  45.         end;
  46.    end; { ADJUSTSCALE }
  47.  
  48. begin { INSYMBOL }
  49. 1: while CH = ' ' do NEXTCH;
  50.    if CHARTP[CH] = ILLEGAL then begin
  51.      NEXTCH;
  52.      ERROR(24); writeln(' char is :: ', ORD(CH) );
  53.      goto 1;
  54.    end;
  55.    case CH OF
  56.  
  57.    'A'..'Z',
  58.    'a'..'z'  :    begin    (* identifier or wordsymbol *)
  59.                     K  := 0;
  60.                     ID := '          ';
  61.                     repeat
  62.                       if K < ALNG then begin
  63.                          K := K+1;
  64.                          ID[K] := UpCase( CH );
  65.                       end;
  66.                       NEXTCH;
  67.                     until (CH <> '_') AND ( CHARTP[CH] in [SPECIAL,ILLEGAL]);
  68.                     I := 1;
  69.                     J := NKW;   (*BINARY SEARCH*)
  70.                     repeat K := (I+J) DIV 2;
  71.                       if ID <= KEY[K] then J := K-1;
  72.                       if ID >= KEY[K] then I := K+1;
  73.                     until I > J;
  74.                     if I-1 > J then SY := KSY[K] else SY := IDENT;
  75.                   end;
  76.  
  77. '0'..'9': begin { NUMBER }
  78.             K := 0;
  79.             INUM := 0;
  80.             SY := INTCON;
  81.             repeat
  82.               INUM := INUM*10 + ORD(CH) - ORD('0');
  83.               K := K+1;
  84.               NEXTCH;
  85.             until CHARTP[CH] <> NUMBER;
  86.             if (K > KMAX) OR (INUM > NMAX) then begin
  87.               ERROR(21);
  88.               INUM := 0;
  89.               K := 0;
  90.             end;
  91.             if CH = '.' then begin
  92.               NEXTCH;
  93.               if CH = '.' then CH := ':'
  94.                 else begin
  95.                   SY := REALCON;
  96.                   RNUM := INUM;
  97.                   E := 0;
  98.                   while CHARTP[CH] = NUMBER do begin
  99.                     E := E-1;
  100.                     RNUM := 10.0*RNUM + (ORD(CH)-ORD('0'));
  101.                     NEXTCH
  102.                  end;
  103.                  if E = 0 then ERROR(40);
  104.                  if CH = 'E' then READSCALE;
  105.                  if E <> 0 then ADJUSTSCALE
  106.                end;
  107.              end else if CH = 'E' then begin
  108.                SY := REALCON;
  109.                RNUM := INUM;
  110.                E := 0;
  111.                READSCALE;
  112.                if E <> 0 then ADJUSTSCALE;
  113.              end;
  114.            end;
  115.  
  116. ':' : begin
  117.         NEXTCH;
  118.         if CH = '=' then begin
  119.           SY := BECOMES;
  120.           NEXTCH;
  121.         end else SY := COLON;
  122.       end;
  123.  
  124. '<' : begin
  125.         NEXTCH;
  126.         if CH = '=' then begin
  127.           SY := LEQ;
  128.           NEXTCH;
  129.         end else if CH = '>' then begin
  130.           SY := NEQ;
  131.           NEXTCH;
  132.         end else SY := LSS;
  133.       end;
  134.  
  135. '>' : begin
  136.         NEXTCH;
  137.         if CH = '=' then begin
  138.           SY := GEQ;
  139.           NEXTCH;
  140.         end else SY := GTR;
  141.       end;
  142.  
  143. '.' : begin
  144.         NEXTCH;
  145.          if CH = '.' then begin
  146.            SY := COLON;
  147.            NEXTCH;
  148.          end else SY := PERIOD;
  149.       end;
  150.  
  151. '''': begin
  152.         K := 0;
  153.      2: NEXTCH;
  154.         if CH = '''' then begin
  155.           NEXTCH;
  156.           if CH <> '''' then goto 3
  157.         end;
  158.         if SX+K = SMAX then FATAL(7);
  159.         STAB[SX+K] := CH;
  160.         K := K+1;
  161.         if CC = 1 then K := 0   (*END OF LINE*)
  162.                   else goto 2;
  163.      3: if K = 1 then begin
  164.           SY := CHARCON;
  165.           INUM := ORD(STAB[SX]);
  166.         end else
  167.           if K = 0 then begin
  168.             ERROR(38);
  169.             SY   := CHARCON;
  170.             INUM := 0;
  171.           end else begin
  172.             SY    := WORD;
  173.             INUM  :=   SX;
  174.             SLENG :=    K;
  175.             SX    := SX+K;
  176.           end;
  177.       end;
  178.  
  179. '(' : begin
  180.         NEXTCH;
  181.         if CH <> '*' then SY := LPARENT
  182.         else begin    (* comment *)
  183.           NEXTCH;
  184.           repeat
  185.             while CH <> '*' do NEXTCH;
  186.             NEXTCH
  187.           until CH = ')';
  188.           NEXTCH;
  189.           goto 1;
  190.         end
  191.       end;
  192.  
  193. '{' : begin            (* comment *)
  194.         while CH <> '}' do NEXTCH;
  195.         NEXTCH;
  196.         goto 1;
  197.       end;
  198.  
  199. '+', '-', '*', '/', ')', '=', ',', '[', ']',  ';' :
  200.       begin
  201.         SY := SPS[CH];
  202.         NEXTCH;
  203.       end;
  204.  
  205. '$', '!', '@', '\', '^', '_', '?', '"', '&', '%' :
  206.       begin
  207.         ERROR(24);
  208.         writeln(' [ $!@\^_?"&%  ]' );
  209.         NEXTCH;
  210.         goto 1;
  211.       end;
  212.    end;
  213. end; { INSYMBOL }
  214.